package com.zbkj.dal.base.enums;


import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.LocalDateTimeUtil;
import com.zbkj.dal.base.enums.show.EnumInterface;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.time.LocalDate;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

@Getter
@AllArgsConstructor
public enum QuotaChangeType implements EnumInterface<String> {

    /**
     * 余额、微信
     */
    QUOTA_RECHARGE("QUOTA_RECHARGE", true, "认购额度", "认购日期"),
    /**
     * 审核完成估价之后，添加额度，创建记录
     */
    PRODUCT_RECYCLE_VALUATION("PRODUCT_RECYCLE_VALUATION", true, "奢品供享（保价）", "生效日期"),
    PRODUCT_RECYCLE_NOT_VALUATION("PRODUCT_RECYCLE_NOT_VALUATION", true, "奢品供享（非保价）", "生效日期"),
    PRODUCT_RECYCLE_RETRIEVAL("PRODUCT_RECYCLE_RETRIEVAL", true, "取回供享奢品", "生效日期"),
    RECYCLE_PRICE_ADJUSTMENT("RECYCLE_PRICE_ADJUSTMENT", true, "估价调整", "生效日期"),
    /**
     * 订单支付完成
     */
    QUOTA_USE("QUOTA_USE", false, "额度使用", "生效日期"),
    /**
     * 订单取消/订单归还完成
     */
    QUOTA_USE_BACK("QUOTA_USE_BACK", false, "额度使用返还", "生效日期"),
    /**
     * 后台调整
     */
    SYSTEM_ADJUSTMENT("SYSTEM_ADJUSTMENT", true, "系统调整", "生效日期"),
    USER_QUOTA_SHARE("USER_QUOTA_SHARE", false, "分享给他人额度", "生效日期"),
    RECEIVE_QUOTA_SHARE("RECEIVE_QUOTA_SHARE", false, "分享他人额度", "生效日期"),
    ;
    private final String code;
    private final Boolean levelCalculate;
    private final String desc;
    private final String pageDesc;

    public static List<String> levelCalculateList() {
        return Arrays.stream(QuotaChangeType.values()).filter(QuotaChangeType::getLevelCalculate).map(QuotaChangeType::getCode).collect(Collectors.toList());
    }

    public static String getDescByCode(String code) {
        if (StringUtils.isBlank(code)) {
            return null;
        }
        return Arrays.stream(QuotaChangeType.values()).filter(t -> StringUtils.equals(t.getCode(), code)).map(QuotaChangeType::getDesc).findFirst().orElse(null);
    }

    public static String spliceDate(String code, LocalDate date) {
        if (Objects.isNull(date)) {
            return null;
        }
        String dateStr = LocalDateTimeUtil.format(date, DatePattern.NORM_DATE_PATTERN);
        if (StringUtils.isBlank(code)) {
            return dateStr;
        }
        return Arrays.stream(QuotaChangeType.values()).filter(t -> StringUtils.equals(t.getCode(), code)).map(q -> q.getPageDesc() + " " + dateStr).findFirst().orElse(dateStr);
    }


    @Override
    public String code() {
        return code;
    }

    @Override
    public String desc() {
        return desc;
    }
}
